/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bluelinelabs.conductor.conductor.manager;

import com.bluelinelabs.conductor.conductor.utile.TextUtils;
import com.bluelinelabs.conductor.conductor.view.AboutDialogView;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.CommonDialog;

/**
 * lipeiquan
 *
 * @since 2021-05-06
 */
public class ObjectManager {
    private static ObjectManager sObjectManager;
    private Text mToolbar;
    private Text mIdTitleAbout;
    private Image mIdFab;

    public static ObjectManager getInstance() {
        synchronized (ObjectManager.class) {
            if (sObjectManager == null) {
                sObjectManager = new ObjectManager();
            }
        }
        return sObjectManager;
    }


    public void setToolbar(Text toolbar) {
        this.mToolbar = toolbar;
    }

    public void setIdTitleAbout(Text Id_title_about) {
        this.mIdTitleAbout = Id_title_about;
        Id_title_about.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Id_title_about.setVisibility(Component.HIDE);
                AboutDialogView aboutDialogView = new AboutDialogView(Id_title_about.getContext());
                aboutDialogView.setDestroyedListener(new CommonDialog.DestroyedListener() {
                    @Override
                    public void onDestroy() {
                        Id_title_about.setVisibility(Component.VISIBLE);
                        if (mIdFab != null) {
                            mIdFab.setVisibility(Component.VISIBLE);
                        }
                    }
                });
                aboutDialogView.show();
            }
        });
    }

    public void changeToolbarContent(String title) {
        if (mToolbar != null && !TextUtils.isEmpty(title)) {
            mToolbar.setText(title);
        }
    }

    public void setIdTitleAboutSetVisibility(int visibility) {
        if (mIdTitleAbout != null) {
            mIdTitleAbout.setVisibility(visibility);
        }
    }

    public void callOnClickTitleAbout() {
        if (mIdTitleAbout != null) {
            mIdTitleAbout.callOnClick();
        }
    }

    public void setHomeControllerImage(Image id_fab) {
        this.mIdFab = id_fab;
    }

    private AnimatorChangeHandlerListener mAnimatorChangeHandlerListener;

    public void addFinishAnimator(AnimatorChangeHandlerListener mAnimatorChangeHandlerListener) {
        this.mAnimatorChangeHandlerListener = mAnimatorChangeHandlerListener;
    }

    public void finishAnimator(boolean isFistStart) {
        if (mAnimatorChangeHandlerListener != null) {
            mAnimatorChangeHandlerListener.cityGridControllerFinishAnimator(isFistStart);
        }
    }

    public interface AnimatorChangeHandlerListener {
        void cityGridControllerFinishAnimator(boolean isFistStart);
    }


}
